/*** manager ***/
package comm;

import db.DataBase;

public class Users {

  private static String[] headers;
  private static String[][] data;

  public static final int HEADER_ID = 0;
  public static final int HEADER_TYPE = 1;
  public static final int HEADER_NAME = 2;
  public static final int HEADER_PASS = 3;

  public static final String TYPE_MANAGER = "m";
  public static final String TYPE_VENDER = "v";

  
  private static void setData() {
    data = DataBase.readData(DataBase.USERS);
    headers = new String[]{
              "ID", "Tipo", "Nome", "Senha"
            };
  }


  public static String[] getHeaders() {
    return headers;
  }

  public static String[][] getData() {
    setData();
    return data;
  }

  public static String[] getData(int row) {
    setData();
    return data[row];
  }

  private static String getID() {
    String id = "";
      id = Integer.toString(((int) (Math.random() * 10000)) + 1);
      for (int i = 0; i < data.length; i++) {
        if (data[i][0].equals(id)) {
          return null;
        }
      }
      return id;
  }

  public static String getValidID() {
    setData();
    String res = null;
    while(res == null) {
      res = getID();
    }
    return res;
  }

}
